#include "stm32f10x.h"



void Reset_Handler(void);
void Default_Handler(void);

#define STACK_TOP  ((void *)0x20001000)


__attribute__ ((section(".isr_vector")))
void (* const __Vectors[])(void) = {
    (void (*)(void))STACK_TOP, // Initial Stack Pointer
    Reset_Handler,             // Reset Handler
    Default_Handler,           // NMI Handler
    Default_Handler,           // HardFault Handler

};

// ????????,?????1
void Default_Handler(void) {
    while(1) {
        // ???????????
    }
}

void delay_ms(uint32_t ms) {
    for(uint32_t i=0; i<ms*100; i++) {
        __NOP();
    }
}

void gpio_init(void) {
    RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // ??GPIOA??
    GPIOA->CRL &= ~(0xFFFF);             // ??PA0~PA3??
    GPIOA->CRL |= 0x3333;                // ??PA0~PA3?????,????50MHz
    // ??????PA1?PA2,????:
    // GPIOA->CRL &= ~( (0xF << 4) | (0xF << 8) ); // ??PA1?PA2??(4?)
    // GPIOA->CRL |= (0x3 << 4) | (0x3 << 8);      // ??PA1?PA2?????,50MHz
}

void Reset_Handler(void) {
    gpio_init();
    while(1) {
        // ??PA1?PA2
        GPIOA->ODR |= (1 << 1) | (1 << 2) | (1 << 3);
        delay_ms(500);

        // ??PA1?PA2
        GPIOA->ODR &= ~((1 << 1) | (1 << 2) | (1 << 3));
        delay_ms(500);
    }
}
